package info.wangyuan.agent.entity.dto;

import info.wangyuan.agent.common.Enum.MessageType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 流式聊天响应DTO
 *
 * @author Albert
 * @since 2025-08-25 20:20:37
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AgentChatResponseDTO {

    /**
     * 响应内容片段
     */
    private String content;

    /**
     * 是否是最后一个片段
     */
    private boolean done;

    /**
     * 消息类型
     */
    private MessageType messageType = MessageType.TEXT;

    /**
     * 数据载荷，用于传递非文本内容
     */
    private String payload;

    /**
     * 时间戳
     */
    private Long timestamp = System.currentTimeMillis();

    public static AgentChatResponseDTO buildEndMessage(MessageType messageType) {

        AgentChatResponseDTO streamChatResponse = new AgentChatResponseDTO();
        streamChatResponse.setContent("");
        streamChatResponse.setDone(true);
        streamChatResponse.setMessageType(messageType);
        return streamChatResponse;
    }

    public static AgentChatResponseDTO buildEndMessage(String content, MessageType messageType) {

        AgentChatResponseDTO streamChatResponse = new AgentChatResponseDTO();
        streamChatResponse.setContent(content);
        streamChatResponse.setDone(true);
        streamChatResponse.setMessageType(messageType);
        return streamChatResponse;
    }

    public static AgentChatResponseDTO build(String content, MessageType messageType) {

        AgentChatResponseDTO streamChatResponse = new AgentChatResponseDTO();
        streamChatResponse.setContent(content);
        streamChatResponse.setDone(false);
        streamChatResponse.setMessageType(messageType);
        return streamChatResponse;
    }

    public AgentChatResponseDTO(String content, boolean done) {
        this.content = content;
        this.done = done;
    }
}
